/*
 * @Date: 2023-07-27 20:33:01
 * @LastEditors: zhangsongwei
 * @LastEditTime: 2023-08-04 15:00:13
 * @FilePath: /z/src/service/tools.ts
 * @description:
 */
/**
 * Created by 叶子 on 2017/7/30.
 * http通用工具函数
 */
import axios from "axios";
import { message } from "antd";

interface IFRequestParam {
  url: string;
  msg?: string;
  config?: any;
  data?: any;
}
/**
 * 公用get请求
 * @param url       接口地址
 * @param msg       接口异常提示
 * @param headers   接口所需header配置
 */
export const get = ({ url, msg = "接口异常", config }: IFRequestParam) => {
  return axios
    .get(url, config)
    .then((res) => res.data)
    .catch((err) => {
      console.log(err);
      message.warn(msg);
    });
};

/**
 * 公用post请求
 * @param url       接口地址
 * @param data      接口参数
 * @param msg       接口异常提示
 * @param headers   接口所需header配置
 */
export const post = ({ url, data, msg = "接口异常", config }: IFRequestParam) =>
  axios
    .post(url, data, config)
    .then((res) => res.data)
    .catch((err) => {
      console.log(err);
      message.warn(msg);
    });
